<template>
  <div class="songs-container">
    <div class="tab-bar">
      <span class="item" :class="{active:tag=='0'}" @click="tag='0'">全部</span>
      <span class="item" :class="{active:tag=='7'}" @click="tag='7'">华语</span>
      <span class="item" :class="{active:tag=='96'}" @click="tag='96'">欧美</span>
      <span class="item" :class="{active:tag=='8'}" @click="tag='8'">日本</span>
      <span class="item" :class="{active:tag=='16'}" @click="tag='16'">韩国</span>
    </div>
    <!-- 底部的table -->
    <table class="el-table playlit-table">
      <thead>
        <th></th>
        <th></th>
        <th>音乐标题</th>
        <th>歌手</th>
        <th>专辑</th>
        <th>时长</th>
      </thead>
      <tbody>
        <tr class="el-table__row" v-for="(item,key) in musiclist" :key="item.key">
          <td>{{key+1}}</td>
          <td>
            <div class="img-wrap">
              <img :src="item.artists[0].picUrl" alt />
              <span class="iconfont icon-play" @click="play(item.id)"></span>
            </div>
          </td>
          <td>
            <div class="song-wrap">
              <div class="name-wrap">
                <span>{{item.name}}</span>
                <span class="iconfont icon-mv"></span>
              </div>
              <span>{{item.album.company}}</span>
            </div>
          </td>
          <td>{{item.artists[0].name}}</td>
          <td>{{item.name}}</td>
          <td>{{item.d}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "songs",
  data() {
    return {
      musiclist: [],
      tag: "0"
    };
  },
  created() {
    axios({
      url: "https://autumnfish.cn/top/song",
      params: {
        type: this.tag
      }
    }).then(res => {
      console.log(res);
      this.musiclist = res.data.data;
      for (let i = 0; i < this.musiclist.length; i++) {
            let time = parseInt(this.musiclist[i].duration / 1000);
            let sec = parseInt((this.musiclist[i].duration / 1000) % 60);
            let min = parseInt(time / 60);
            this.musiclist[i].d = min + ":" + sec;
            console.log(this.musiclist[i].d);
          }
      // this.toplist = res.data.playlists[0];
    });
  },
  methods: {
    play(id) {
      axios({
        url: "https://autumnfish.cn/song/url",
        params: {
          id
        }
      }).then(res => {
        let url = res.data.data[0].url;
        this.$parent.songurl = url;
        console.log(res);
      });
    }
  },
  watch: {
    tag() {
      axios({
        url: "https://autumnfish.cn/top/song",
        params: {
          type: this.tag
        }
      }).then(res => {
        console.log(res.data.data);
        this.musiclist = res.data.data;
        // this.toplist = res.data.playlists[0];
      });
    }
  }
};
</script>

<style >
</style>
